package com.zte.market.control;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zte.market.model.MarketOrderCondition;
import com.zte.market.model.MarketOrders;
import com.zte.market.service.MarketOrdersService;
import com.zte.util.OperatorLog;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 营销模块订单审核功能
 */

@RestController
@RequestMapping("/orderExamine")
public class OrderExamineAction {
    @Autowired
    private MarketOrdersService ordersService;
    //获取审核页面分页信息
    @PostMapping
    @OperatorLog(operate="多条件查询订单审核分页", module="订购单审核")
    public ResultMessage getOrderExamineInfo(@RequestBody MarketOrderCondition condition){
        int pageSize = condition.getPageSize();
        int pageNum = condition.getPageNum();
        if (pageSize <= 0) pageSize = 5;
        if (pageNum <= 0) pageNum = 1;
        if(condition.getCheckId()==null) {
            return new ResultMessage(400,false,"无审核人信息",null);
        }else {
            condition.setStatus(2);
            PageModel<MarketOrders> pageModel = new PageModel<>();
            pageModel.setPageNum(pageNum);
            pageModel.setPageSize(pageSize);
            return new ResultMessage(200, true, "scuess", ordersService.pageOrderExamineInfoByCondition(pageModel, condition));
        }
    }
    //审核提交
    @PutMapping
    @OperatorLog(operate="确定审核状态", module="订购单审核")
    public ResultMessage ExamineOrder(@RequestBody MarketOrders orders){
        boolean success=ordersService.update(new LambdaUpdateWrapper<MarketOrders>().eq(MarketOrders::getOrderid,orders.getOrderid())
                .set(MarketOrders::getCheckid,orders.getCheckid())
                .set(MarketOrders::getChectime,new Date())
                .set(MarketOrders::getStatus,orders.getStatus())
                .set(MarketOrders::getOpinion,orders.getOpinion()));
        if(success){
            return new ResultMessage(200,true,"审核成功",null);
        }else {
            return new ResultMessage(400,false,"审核失败",null);
        }
    }
}
